<?php
class Know_model extends CI_Model{
	function __construct(){
		parent::__construct();
	}

	public function action(){
		
		$data['uid'] = $this->auth->uid;
		$data['uname'] = $this->auth->uname;
		$data['content'] = $this->form_validation->set_value('content');
		$data['title'] = $this->form_validation->set_value('title');
		$data['status'] = $this->form_validation->set_value('status');
		$data['time'] = $this->form_validation->set_value('time') ? $this->form_validation->set_value('time') : date('Y-m-d H:i:s');
		if($this->db->insert('know',$data)){
			return array('status'=>true);
		}else{
			return array('status'=>false,'msg'=>'添加失败，可能网络出错！');
		}
	}
	
	public function update($id){
		
		$data['content'] = $this->form_validation->set_value('content');
		$data['title'] = $this->form_validation->set_value('title');
		$data['status'] = $this->form_validation->set_value('status');
		$data['time'] = $this->form_validation->set_value('time') ? $this->form_validation->set_value('time') : date('Y-m-d H:i:s');
		$this->db->where('id',$id);
		if($this->db->update('know',$data)){
			return array('status'=>true);
		}else{
			return array('status'=>false,'msg'=>'添加失败，可能网络出错！');
		}
	}

	public function get_know($start=0,$limit=null,$status=false){
		$this->db->order_by('time','DESC');
		$this->db->limit($limit,$start);

		if($status){
			$this->db->where('status',1);
		}

		$query = $this->db->get('know');
		if($query->num_rows){
			return $query->result_id();
		} else {return false;}
	}

	public function get_know_byid($id){
		
		$this->db->where('id',$id);

		$query = $this->db->get('know');
		if($query->num_rows){
			return $query->row();
		} else {return false;}
	}

	public function get_know_num($status=false){

		if($status){
			$this->db->where('status',1);
		}


		return $this->db->count_all_results('know');
	}

	
}